#include <sys/system.h>
#include <sys/string.h>

#include <stdarg.h>
#include <stdio.h>
#include <string.h>

void pt_assert(const char* str, int line)
{

}

void pt_kprintf(const char *fmt, ...)
{

}

int pt_strncasecmp(const pt_int8_t *s1, const pt_int8_t *s2, pt_size_t len)
{
	unsigned int x2;
	unsigned int x1;
	const pt_int8_t *end = s1 + len;

	while (1) {
		if ((s1 >= end)) {
			return 0;
		}

		x2 = *s2 - 'A'; if ((x2 < 26u)) {
							x2 += 32;
						}
		x1 = *s1 - 'A'; if ((x1 < 26u)) {
							x1 += 32;
						}
		s1++; s2++;

		if ((x2 != x1)) {
			break;
		}

		if ((x1 == (unsigned int) - 'A')) {
			break;
		}
	}

	return x1 - x2;
}

pt_size_t pt_strncmp(const pt_int8_t *cs, const pt_int8_t *ct, pt_size_t count)
{
	return strncmp(cs, ct, count);
}

pt_size_t pt_strlen(const pt_int8_t *src)
{
	return strlen(src);
}

pt_int8_t * pt_strncpy(pt_int8_t *dest, const pt_int8_t *src, pt_size_t n)
{
	pt_int8_t *dscan;
	const pt_int8_t *sscan;

	dscan = dest;
	sscan = src;
	while (n > 0) {
		--n;
		if ((*dscan++ = *sscan++) == '\0') {
			break;
		}
	}

	while (n-- > 0)
		*dscan++ = '\0';

	return dest;
}

pt_int8_t * pt_strdup(const pt_int8_t *str)
{
	pt_int8_t *tmp = (pt_int8_t *)pt_malloc(strlen(str) + 1);
	if (!tmp) {
		return 0;
	}
	strcpy(tmp, str);

	return tmp;
}

void pt_snprintf(pt_int8_t *buffer, pt_size_t count, const pt_int8_t *fmt, ...)
{
	va_list args;

	va_start(args, fmt);
	_vsnprintf(buffer, count, fmt, args);
	va_end(args);
}

void pt_sprintf(pt_int8_t *buffer, const pt_int8_t *fmt, ...)
{
	va_list args;

	va_start(args, fmt);
	vsprintf(buffer, fmt, args);
	va_end(args);
}